package com.cskaoyan.service;

import com.cskaoyan.domain.MarketStorage;
import com.cskaoyan.mapper.MarketStorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.Date;

@Service
public class StorageServiceImpl implements StorageService {
@Autowired
    MarketStorageMapper marketStorageMapper;

    @Override
    public MarketStorage store(MultipartFile file, String fileName) {
        String url = "http://localhost:8083/wx/storage/fetch/" + fileName;
        MarketStorage marketStorage = new MarketStorage();
        marketStorage.setKey(fileName);
        marketStorage.setName(file.getOriginalFilename());
        marketStorage.setSize((int) file.getSize());
        marketStorage.setType(file.getContentType());
        marketStorage.setAddTime(LocalDateTime.now());
        marketStorage.setUpdateTime(LocalDateTime.now());
        marketStorage.setUrl(url);
        marketStorage.setDeleted(false);
        marketStorageMapper.insert(marketStorage);
        return marketStorage;
    }
}
